package st.business.tepth.business.goodscheck;

import java.util.List;

import st.business.tepth.base.OnDataConvertListener;
import st.business.tepth.business.bean.MaterialCheckBean;

/**
 * Author: shadow
 * Email:  1025431817@qq.com
 * Time:   2019-02-26 15:58
 */

public class GoodsCheckPresenter extends GoodsCheckContract.Presenter {
    private final GoodsCheckContract.View mView;
    private final GoodsCheckContract.Model mModel;

    public GoodsCheckPresenter(GoodsCheckContract.View view) {
        mView = view;
        mModel = new GoodsCheckModel();
    }

    @Override
    void getData(String token) {
        addDisposable(mModel.getData(token,
                new OnDataConvertListener<List<MaterialCheckBean>>() {
                    @Override
                    public void convert(List<MaterialCheckBean> list) {
                        if (mView != null) {
                            mView.showData(list);
                        }
                    }

                    @Override
                    public void error(int code, String msg) {
                        if (mView != null) {
                            mView.showData(null);
                        }
                    }
                }));
    }

    @Override
    void check(String token, String items, String taskId, final int status) {
        addDisposable(mModel.check(token, items, taskId, status,
                new OnDataConvertListener<String>() {
                    @Override
                    public void convert(String s) {
                        mView.checkSucceed(status == 1 ? "审批成功" : "驳回成功");
                    }

                    @Override
                    public void error(int code, String msg) {
                        mView.showError(msg);
                    }
                },
                new OnDataConvertListener<List<MaterialCheckBean>>() {
                    @Override
                    public void convert(List<MaterialCheckBean> list) {
                        if (mView != null) {
                            mView.showData(list);
                        }
                    }

                    @Override
                    public void error(int code, String msg) {
                        mView.showError(msg);
                    }
                }));
    }
}
